import { Node, _decorator } from 'cc';
import TipsComp from './component/TipsComp';
import UILayer from './UILayer';
import { ViewParams } from './ViewDefine';

const TipsPrefabPath: string = 'ui/common/tips/prefab/tips';
const { ccclass, property } = _decorator;

@ccclass('TipsLayer')
export default class TipsLayer extends UILayer {

    show(content: string): void {
        var viewParams = new ViewParams();
        viewParams.uuid = this.getUuid(TipsPrefabPath);
        viewParams.prefabPath = TipsPrefabPath;
        viewParams.payload = { content: content };
        viewParams.callbacks = {};
        viewParams.valid = true;

        // this.createNode(viewParams.prefabPath, (node: Node) => {
        //     viewParams.node = node;

        //     let comp: UIDelegateComp = node.addComponent(UIDelegateComp);
        //     comp.viewParams = viewParams;

        //     this.addUI(viewParams);
        // });

    }

    protected addUI(viewParams: ViewParams) {
        let childNode: Node = super.addUI(viewParams);

        let tipCom: TipsComp = childNode.getComponent(TipsComp)!;
        childNode.active = true;
        tipCom.toast(viewParams.payload.content);

        return childNode;
    }
}